package fragmentson;

import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.wq.cycling.R;

import activity.SonActivity;
import co.lujun.androidtagview.TagContainerLayout;
import fragmentson.backhandle.BackHandledFragment;

/**
 * 维修店评论页
 * author：wangqi on 2017/4/26 17:48
 * email：773630555@qq.com
 */
public class ShopComment extends BackHandledFragment {

	private View rootView;
	private TagContainerLayout tag;
	private String[] str={"态度很好","修的又快又好","价格很便宜","一般般","好！好！好！","一般般","不回来下一次了","坐地起价","价格很便宜","一般般","好！好！好！"};
    private ImageView iv_star1,iv_star2,iv_star3,iv_star4,iv_star5;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		rootView = getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_shopcomment, null);
		initView();
		return rootView;
	}

	public void initView(){
		((TextView) rootView.findViewById(R.id.tv_title)).setText(R.string.my_comment);
		tag = ((TagContainerLayout) rootView.findViewById(R.id.tag));
		tag.setBackgroundColor(Color.alpha(0));//整个背景色
		tag.setBorderColor(Color.alpha(0));//整个容器的边框色，因为有默认值，所以我自己设为透明
		for(int i=0;i<str.length;i++) {
			addView(str[i]);
		}
		rootView.findViewById(R.id.tv_submit).setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				((SonActivity) getActivity()).backTask();
			}
		});
        (iv_star1 = ((ImageView) rootView.findViewById(R.id.iv_star1))).setOnClickListener(listener);
        (iv_star2 = ((ImageView) rootView.findViewById(R.id.iv_star2))).setOnClickListener(listener);
        (iv_star3 = ((ImageView) rootView.findViewById(R.id.iv_star3))).setOnClickListener(listener);
        (iv_star4 = ((ImageView) rootView.findViewById(R.id.iv_star4))).setOnClickListener(listener);
        (iv_star5 = ((ImageView) rootView.findViewById(R.id.iv_star5))).setOnClickListener(listener);

	}

	private void addView(String text) {
		//添加自定义布局
		View inflate = LayoutInflater.from(getActivity()).inflate(R.layout.tag_item, null);
		View view = inflate.findViewById(R.id.view);
		TextView textView = (TextView) inflate.findViewById(R.id.textView);
		textView.setText(text);
		view.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				 v.setBackgroundResource(R.drawable.corner_view_yellow);
			}
		});
		tag.addView(inflate);
	}

	private View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
			iv_star5.setImageResource(R.mipmap.icon_unstared);
			iv_star4.setImageResource(R.mipmap.icon_unstared);
			iv_star3.setImageResource(R.mipmap.icon_unstared);
			iv_star2.setImageResource(R.mipmap.icon_unstared);
			iv_star1.setImageResource(R.mipmap.icon_unstared);
            switch (v.getId()){
                case R.id.iv_star5:
                    iv_star5.setImageResource(R.mipmap.icon_stared);
                case R.id.iv_star4:
                    iv_star4.setImageResource(R.mipmap.icon_stared);
                case R.id.iv_star3:
                    iv_star3.setImageResource(R.mipmap.icon_stared);
                case R.id.iv_star2:
                    iv_star2.setImageResource(R.mipmap.icon_stared);
                case R.id.iv_star1:
                    iv_star1.setImageResource(R.mipmap.icon_stared);
                default:
                    break;
            }
        }
    };

	public static ShopComment newInstance() {
		ShopComment fragment = new ShopComment();
		return fragment;
	}

	@Override
	public boolean onBackPressed() {
		return false;
	}
	
}
